package com.springboot.study.common;

import java.io.Serial;
import java.io.Serializable;

public class Result implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    private String code;
    private String message;
    private Object data;
    public Result() {
        this.code = "200";
        this.message = "操作成功";
    }

    public Result(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(String code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static Result success(Object data) {
        return new Result("200", "操作成功", data);
    }

    public static Result success() {
        return new Result("200", "操作成功");
    }

    public static Result error(String code, String message) {
        return new Result(code, message);
    }

    public static Result error(String message) {
        return new Result("500", message);
    }

    public static Result error() {
        return new Result("500", "操作失败");
    }

}
